export default {
	data() {
		return {
			totalCount: 99,
			list: [],
			queryParams: {
				pageIndex: 1,
				pageSize: 10,
			},
			triggered: false,
			api: '',
			reqStatus: 0,
			_freshing: false
		}
	},
	methods: {
		async refresherrefresh() {
			this.triggered = true
			if (this._freshing) return;
			this._freshing = true;
			await this.init(this.api)
			this.triggered = false;
			this._freshing = false;
		},
		refresherrestore() {
			this.triggered = 'restore'; // 需要重置
		},
		async init(api, params) {
			this.reqStatus = 0
			this.queryParams.pageIndex = 1;
			await this.getList(api, params)
		},
		async getList(api, params) {
			this.reqStatus = 1
			this.api = api
			this.queryParams = Object.assign(this.queryParams, params)
			let {
				result
			} = await this.$http.get(this.api, this.queryParams)
			if (this.queryParams.pageIndex > 1) {
				this.list.push(...result.items)
			} else {
				this.list = result.items
			}
			this.reqStatus = 0
			this.totalCount = result.totalCount

		},
		// scroll-view到底部加载更多
		scrolltolower() {
			if (this.list.length >= this.totalCount) {
				this.reqStatus = 2
			}
			if (this.reqStatus === 2) return
			this.queryParams.pageIndex += 1
			this.getList(this.api, this.queryParams)
		}
	},
}